home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk2.zip / LST11-22.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  77 lines

  1. ;
  2. ; *** Listing 11-22 ***
  3. ;
  4. ; Compares two word-sized arrays of equal length to see
  5. ; whether they differ, and if so where, using LODSW and
  6. ; SCASW.
  7. ;
  8.     jmp    Skip
  9. ;
  10. WordArray1    dw    100 dup (1), 0, 99 dup (2)
  11. ARRAY_LENGTH_IN_WORDS    equ    (($-WordArray1)/2)
  12. WordArray2    dw    100 dup (1), 100 dup (2)
  13. ;
  14. ; Returns pointers to the first locations at which two
  15. ; word-sized arrays of equal length differ, or zero if
  16. ; they're identical.
  17. ;
  18. ; Input:
  19. ;    CX = length of the arrays (they must be of equal
  20. ;        length)
  21. ;    DS:SI = the first array to compare
  22. ;    ES:DI = the second array to compare
  23. ;
  24. ; Output:
  25. ;    DS:SI = pointer to the first differing location in
  26. ;        the first array if there is a difference,
  27. ;        or SI=0 if the arrays are identical
  28. ;    ES:DI = pointer to the first differing location in
  29. ;        the second array if there is a difference,
  30. ;        or DI=0 if the arrays are identical
  31. ;
  32. ; Registers altered: AX, SI, DI
  33. ;
  34. ; Direction flag cleared
  35. ;
  36. ; Note: Does not handle arrays that are longer than 32K
  37. ;    words or cross segment boundaries.
  38. ;
  39. FindFirstDifference:
  40.     cld
  41.     jcxz    FindFirstDifferenceSame
  42.                 ;if there's nothing to
  43.                 ; check, we'll consider the
  44.                 ; arrays to be the same.
  45.                 ; (If we let LOOP
  46.                 ; execute with CX=0, we'll
  47.                 ; get 64 K repetitions)
  48. FindFirstDifferenceLoop:
  49.     lodsw
  50.     scasw            ;compare the next two words
  51.     jnz    FindFirstDifferenceFound
  52.                 ;the arrays differ
  53.     loop    FindFirstDifferenceLoop
  54.                 ;the arrays are the
  55.                 ; same so far
  56. FindFirstDifferenceSame:
  57.     sub    si,si        ;indicate that the strings
  58.     mov    di,si        ; are identical
  59.     ret
  60. FindFirstDifferenceFound:
  61.     dec    si        ;the arrays differ, so
  62.     dec    si        ; point back to first
  63.     dec    di        ; difference in both arrays
  64.     dec    di
  65.     ret
  66. ;
  67. Skip:
  68.     call    ZTimerOn
  69.     mov    si,offset WordArray1    ;point to the two
  70.     mov    di,ds            ; arrays to be
  71.     mov    es,di            ; compared
  72.     mov    di,offset WordArray2    
  73.     mov    cx,ARRAY_LENGTH_IN_WORDS
  74.                     ;# of words to check
  75.     call    FindFirstDifference    ;see if they differ
  76.     call    ZTimerOff
  77.